<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<ui:composition template="_notaFiscal.xhtml">
	<ui:define name="corpo"><br />

		<div id="conteudo">

			<h:form id="form">

				<h2>
					<h:outputText value="CADASTRAR NOTA FISCAL"
						rendered="#{empty notaFiscalBean.nota.id}" />
					<h:outputText value="EDITAR NOTA FISCAL"
						rendered="#{not empty notaFiscalBean.nota.id}" />
				</h2>
				<hr /><br />

				<p:messages id="msg" />
				
				<p:fieldset legend="Dados da Nota Fiscal">
				
				<h:panelGrid columns="4">
								
				<h:outputLabel value="Número: " for="numero" />
				<p:inputText id="numero" value="#{notaFiscalBean.nota.numero}">
					<p:ajax event="change"/>
				</p:inputText>
				
				<h:outputLabel value="Fornecedor: " for="fornecedor" />
					<h:selectOneMenu value="#{notaFiscalBean.nota.fornecedor}" converter="genericConverter">
						<f:selectItem itemLabel="::Selecione::" noSelectionOption="true" />
						<f:selectItems value="#{fornecedorBean.fornecedores}" var="fornecedor" itemLabel="#{fornecedor.nome}" itemValue="#{fornecedor}" />
				</h:selectOneMenu>
				
				<h:outputLabel value="Data de Emissão: " />
				<p:calendar value="#{notaFiscalBean.nota.data.time}">
					<f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" />
				</p:calendar>
				
				<h:outputLabel value="Empenho: " for="empenho" />
					<h:selectOneMenu value="#{notaFiscalBean.nota.empenho}" converter="genericConverter" required="true" requiredMessage="Informe o número de Empenho da NF">
						<f:selectItem itemLabel="::Selecione::" noSelectionOption="true" />
						<f:selectItems value="#{empenhoBean.empenhos}" var="empenho" itemLabel="#{empenho.numero}" itemValue="#{empenho}" />
				</h:selectOneMenu>	
								
				<h:outputLabel value="Recebido: " />
				<p:calendar value="#{notaFiscalBean.nota.recebido.time}">
					<f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" />
				</p:calendar>
				
				<h:outputLabel value="Status: " for="status" />
				<h:selectOneMenu id="status" value="#{notaFiscalBean.nota.status}">
					<f:selectItem itemLabel="::Selecione::" noSelectionOption="true" ></f:selectItem>
					<f:selectItem itemLabel="Recebido" itemValue="Recebido" />
					<f:selectItem itemLabel="Pendente" itemValue="Pendente" />
					<f:selectItem itemLabel="Aguardando Material" itemValue="Aguardando Material" />
				</h:selectOneMenu>
				
				<h:outputLabel value="Valor Total: " for="valor" />
				<p:inputText id="valor" value="#{notaFiscalBean.nota.valor_total}" required="true" requiredMessage="Informe o Valor Total da Nota">
					<f:convertNumber pattern="#,##0.00" />
					<p:ajax event="change" />
				</p:inputText><br />
				
<!-- 				<div style="float: right; text-align: left; "> -->
<!-- 				<br /><br /> -->
<!-- 						<h:outputLabel value="Observação: " for="obs" /> -->
<!-- 						<p:inputTextarea id="obs" value="#{notaFiscalBean.nota.obs}" -->
<!-- 							style="width: 480px"> -->
<!-- 							<f:ajax event="change" /> -->
<!-- 						</p:inputTextarea> -->
<!-- 				</div><br /> -->

				</h:panelGrid>

				</p:fieldset><br />
				
				<p:fieldset legend="Dados do Produto">
				
				<h:panelGrid columns="2">

					<h:outputLabel value="Produto: " for="produto" />
					<h:selectOneMenu value="#{notaFiscalBean.idProduto}" style="size: 200px;">
						<f:selectItem itemLabel="::Selecione::" noSelectionOption="true" />
						<f:selectItems value="#{produtoBean.produtos}" var="produto"
							itemValue="#{produto.id}" itemLabel="#{produto.nome}" />
						<f:ajax event="change" />
					</h:selectOneMenu>
					
					<h:outputLabel value="Marca: " />
					<p:inputText value="#{notaFiscalBean.item.marca}">
						<f:ajax event="change" />
					</p:inputText>

					<h:outputLabel value="Valor Unitário: " for="valorUnit" />
					<p:inputText id="valorUnit" value="#{notaFiscalBean.item.valor_unit}">
						<f:convertNumber pattern="#,##0.00" />
						<p:ajax event="change" />
					</p:inputText>

					<h:outputLabel value="Quantidade: " />
					<p:inputText value="#{notaFiscalBean.item.quantidade}" size="8">
						<f:ajax event="change" />
					</p:inputText>

					<p:commandButton value="Guarda Item" action="#{notaFiscalBean.guardaItem}" ajax="false">
							<f:ajax render="@form" />
					</p:commandButton>

					</h:panelGrid>	

				</p:fieldset>
				
						<p:dataTable id="listNf" value="#{notaFiscalBean.nota.itens}" var="item"
							paginator="true" rows="8"
							style="font-size: 12px">

							<p:column headerText="Produto">
								<h:outputText value="#{item.produto.nome}" />
							</p:column>
							
							<p:column headerText="Marca">
								<h:outputText value="#{item.marca}" />
							</p:column>

							<p:column headerText="Preço">
								<h:outputText value="#{item.valor_unit}">
									<f:convertNumber type="currency" currencySymbol="R$" locale="pt_BR" pattern="#,##0.00" />
								</h:outputText>	
							</p:column>

							<p:column headerText="Quantidade">
								<h:outputText value="#{item.quantidade}" />
							</p:column>
							
							<p:column headerText="TOTAL">
								<h:outputText value="#{item.total}">
									<f:convertNumber type="currency" currencySymbol="R$" locale="pt_BR" pattern="#,##0.00" />
								</h:outputText>	
							</p:column>

						</p:dataTable><br />
			
			<div align="center">
			<p:commandButton alt="Gravar" value="Gravar Nota Fiscal" style="float: center; text-align: center;"
				action="#{notaFiscalBean.grava}" ajax="false">
				<f:ajax render="@form" />
			</p:commandButton>
			</div>

			</h:form>
				
		</div>


	</ui:define>
</ui:composition>
</html>